package com.thomas.generator.util;

//import org.springframework.validation.BindingResult;
//import org.springframework.validation.ObjectError;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xutao
 * @Package com.thomas.generator.util
 * @Description: ${todo}
 * @date 2019/12/11 18:49
 */
public class ResultJsonUtil {


    private static final String CODE="code";
    private static final String MSG="msg";
    private static final String SUCCESS_CODE="0";
    private static final String ERROR_CODE="1";
    private static final String SUCCESS_MSG="ok";
    public static final String COUNT="count";
    public static final String DATA="data";
    public static Map<String,Object> getSuccessResult(){
        Map<String,Object> result = new HashMap<String,Object>();
        result.put(CODE,SUCCESS_CODE);
        result.put(MSG,SUCCESS_MSG);
        return result;
    }

    public static Map<String,Object> getErrorResult(String errorMsg){
        Map<String,Object> result = new HashMap<String,Object>();
        result.put(CODE,ERROR_CODE);
        result.put(MSG,errorMsg);
        return result;
    }


    /*public static Map<String,Object> analyzeError(BindingResult binding){
        Map<String, Object> result = getErrorResult("");
        List<ObjectError> allErrors = binding.getAllErrors();
        StringBuffer sb = new StringBuffer();
        for (ObjectError objectError : allErrors) {
            sb.append(objectError.getDefaultMessage() + "\n");
        }
        result.put(MSG, sb.toString());
        return result;
    }*/
}
